package model;

import java.util.HashMap;
import java.util.Map;


/**
 * One of the three User types, this represents an individual
 * who registers with the system to bid on items.
 * 
 * @author Daniel Bartholomew
 *
 */
public class Bidder extends User {
		
	private static int next_id_no = 1;
	
	private final int my_id_no;
	
	private final HashMap<Item, Double> my_bids;
	
	public Bidder(final String name) {
		this(name, next_id_no);
	}
	
	/**
	 * Should only be used by Control when loading Bidders from file.
	 */
	protected Bidder(final String name, final int id_no) {
		super(name);
		my_bids = new HashMap<Item, Double>();
		my_id_no = id_no;
		if (id_no >= next_id_no) {
			next_id_no = (id_no + 1);
		}
	}
	
	public int getID() {
		return my_id_no;
	}
	
	/**
	 * Stores an Item along with the price bid on it.
	 * If the item has already been added, the new price overwrites the old.
	 * @return true if the bid price is equal to or greater than the minimum, false otherwise.
	 */
	public boolean newBid(final Item item, final double price) {
		if (price >= item.getMinPrice()) {
			my_bids.put(item, new Double(price));
			return true;
		}
		return false;
	}
	
	public Map<Item, Double> getBids() {
		return my_bids;
	}
	
}
